<?php

namespace IDock\Insurance\MACN\Response;

use IDock\Insurance\HBIC\Response\AllHBICResponse;
use IDock\Printer\PolicyPaymentPrinter;
use IDock\Http\Response;

class InsurancePayUrlResponse extends AllMACNResponse
{
    public function printerInit(): Response
    {
        $policyPaymentPrinter = new PolicyPaymentPrinter();

        $data = $this->getBody() ?? [];
        $url = $data['body']['baseInfo']['payUrl'] ?? '';
        $msgInfo = $data['body']['baseInfo']['msgInfo'] ?? '';
        if(empty($url)){
            $error = '获取支付链接失败';
            if(!empty($msgInfo)){
                $error = $msgInfo;
            }
            $this->setError($error);
            $this->printer = $policyPaymentPrinter;
            return $this;
        }
        $this->setCode('200');
        $policyPaymentPrinter->payUrl = $url;

        $this->printer = $policyPaymentPrinter;
        return $this;
    }
}